#-*- coding: utf-8 -*-

#This file is part of pyLot library.
#
# pyLot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyLot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyLot.  If not, see <http://www.gnu.org/licenses/>.

__author__ = u'Guillaume Baty'
__copyright__ = u"Copyright 2011-2012 (C) andheo"
__credits__ = [u'Guillaume Baty']
__license__ = "GNU Lesser General Public License"

__all__ = ['CliModifierExtensibleToolBox']

from traits.api import implements
from pyLot.cli import ICliModifier

class CliModifierExtensibleToolBox(object):
  implements(ICliModifier)

  def __init__(self, parser):
    self.parser = parser
    group = self.parser.add_argument_group('Graphical options')
    group.add_argument("--load-toolwidget", help="load specified toolwidget if available",
                       action="store", metavar='identifier')
    group.add_argument("--list-toolwidgets", help="list available toolwidgets",
                       action="store_true")
    group.add_argument("--quit-gui", help="quit Graphical User Interface",
                       action="store_true")

  def parseBefore(self, namespace):
    pass

  def parseClass(self, namespace, target):
    u"""
    This method is called before target instantiation.
    All work done here will be available at target instantiation (__init__)
    target is a class
    """
    pass

  def parseInstance(self, namespace, target):
    u"""
    This method is called after target instantiation.
    target is an instance
    """
    if target is None :
      return
    if namespace.load_toolwidget :
      target.showAppli(namespace.load_toolwidget)
    if namespace.list_toolwidgets :
      print 'Available toolwidgets :'
      for identifier in target.toolwidget_classes.keys():
        print '  -', identifier
    if namespace.quit_gui :
      target.close()

  def parseAfter(self, namespace, target):
    pass

  def parseStop(self, namespace):
    pass


class CliModifierDebugExtensibleToolBox(object):
  implements(ICliModifier)

  def __init__(self, parser):
    self.parser = parser
    group = self.parser.add_argument_group('Graphical options')
    group.add_argument("--test-toolkit", help="show test toolkit",
                       action="store_true")
    group.add_argument("--launch-gui-test", help="Launch gui test _test_NAME",
                       action="store", metavar="NAME")

  def parseBefore(self, namespace):
    pass

  def parseClass(self, namespace, target):
    u"""
    This method is called before target instantiation.
    All work done here will be available at target instantiation (__init__)
    target is a class
    """
    if namespace.test_toolkit :
      target.TestToolkit = 1

  def parseInstance(self, namespace, target):
    u"""
    This method is called after target instantiation.
    target is an instance
    """
    if target is None :
      return
    if namespace.launch_gui_test :
      raise NotImplementedError

  def parseAfter(self, namespace, target):
    pass

  def parseStop(self, namespace):
    pass

if __name__ == '__main__' :
  pass
